//
// Created by bianzheng on 2022/6/14.
//

#ifndef REC2_MIPS_SAMPLERATING_HPP
#define REC2_MIPS_SAMPLERATING_HPP

#include <vector>
#include <spdlog/spdlog.h>

#include "ConvertRatings.hpp"

namespace Rec2MIPS {

    void SampleRating(const std::vector<RatingNum> &total_rating_l,
                      const std::pair<int, int> &origin_stat,
                      const std::pair<int, int> &sample_stat,
                      std::vector<RatingNum> &sample_rating_l) {
        const int origin_n_user = origin_stat.first;
        const int sample_n_user = sample_stat.first;
        if (origin_n_user < sample_n_user) {
            spdlog::error("original n_user smaller than sample n_user, program exit");
            exit(-1);
        }

        const int origin_n_item = origin_stat.second;
        const int sample_n_item = sample_stat.second;
        if (origin_n_item < sample_n_item) {
            spdlog::error("origin n_item smaller than sample n_item, program exit");
            exit(-1);
        }

        sample_rating_l.clear();
        const size_t n_total_rating = total_rating_l.size();

        for (size_t ratingID = 0; ratingID < n_total_rating; ratingID++) {
            const int userID = total_rating_l[ratingID].userID_;
            const int itemID = total_rating_l[ratingID].itemID_;
            const double rating = total_rating_l[ratingID].rating_;
            if (userID < sample_n_user && itemID < sample_n_item) {
                sample_rating_l.emplace_back(userID, itemID, rating);
            }
        }
    }

}
#endif //REC2_MIPS_SAMPLERATING_HPP
